from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
import os.path
import time

path = os.path.join(os.path.abspath(os.path.dirname('第3题')), 'html','注册实例.html')
driver = webdriver.Chrome()
driver.get(path)

user = driver.find_element(By.ID,'user')
user.send_keys('a123')

password = driver.find_element(By.ID,'password')
password.send_keys('aa1234')

tel = driver.find_element(By.ID,'tel')
tel.send_keys('18871185432')

email = driver.find_element(By.ID,'email')
email.send_keys('148256@qq.com')

time.sleep(3)
register_user = driver.find_element(By.XPATH,'//*[@id="zc"]/fieldset/button')
register_user.click()

select = driver.find_element(By.ID,"select")
select = Select(select)
time.sleep(2)
select.select_by_index(1)
time.sleep(2)
select.select_by_value('gz')
time.sleep(2)
select.select_by_visible_text('上海')

idframe1 = driver.find_element(By.ID,'idframe1')
driver.switch_to.frame(idframe1)

userA = driver.find_element(By.ID,'userA')
userA.send_keys('a123')

passwordA = driver.find_element(By.ID,'passwordA')
passwordA.send_keys('aa1234')

telA = driver.find_element(By.ID,'telA')
telA.send_keys('18871185432')

emailA = driver.find_element(By.ID,'emailA')
emailA.send_keys('148256@qq.com')

register_user1 = driver.find_element(By.XPATH,'//*[@id="zc"]/fieldset/button')
register_user1.click()

selectA = driver.find_element(By.ID,"selectA")
select = Select(selectA)
time.sleep(2)
select.select_by_index(1)
time.sleep(2)
select.select_by_value('gz')
time.sleep(2)
select.select_by_visible_text('A上海')

driver.switch_to.default_content()
myframe2 = driver.find_element(By.NAME,'myframe2')
driver.switch_to.frame(myframe2)

userB = driver.find_element(By.ID,'userB')
userB.send_keys('a1234')

passwordB = driver.find_element(By.ID,'passwordB')
passwordB.send_keys('aa12345')

telB = driver.find_element(By.ID,'telB')
telB.send_keys('18871185435')

emailB = driver.find_element(By.ID,'emailB')
emailB.send_keys('14825678@qq.com')

register_user2 = driver.find_element(By.XPATH,'//*[@id="zc"]/fieldset/button')
register_user2.click()

selectB = driver.find_element(By.ID,"selectB")
select = Select(selectB)
time.sleep(2)
select.select_by_index(1)
time.sleep(2)
select.select_by_value('gz')
time.sleep(2)
select.select_by_visible_text('上海B')



time.sleep(3)
driver.quit()